/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ArticulosAlmacenView.java
 *
 * Created on 09/12/2009, 04:54:03 PM
 */

package vista;

import controlador.IArticulosAlmacenController;
import modelo.IArticulosAlmacen;
import modelo.IArticulosAlmacenModel;
/**
 *
 * @author LEONIC
 */
public class ArticulosAlmacenView extends javax.swing.JFrame implements IArticulosAlmacenView{

    private IArticulosAlmacenModel model;
    private IArticulosAlmacenController controller;

    private ArticulosAlmacenTableModel tableModel;
    private JPanelArticulosAlmacen panelArticulosAlmacen;

    /** Creates new form ArticulosAlmacenView */
    public ArticulosAlmacenView() {
        tableModel=new ArticulosAlmacenTableModel();
        initComponents();

        this.panelArticulosAlmacen=new JPanelArticulosAlmacen(this);
        this.panelabajo.add(this.panelArticulosAlmacen);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTableArticulosAlmacen = new javax.swing.JTable();
        panelabajo = new javax.swing.JPanel();

        setTitle("Gestión de compras/ventas/devoluciones");

        jTableArticulosAlmacen.setModel(tableModel);
        jTableArticulosAlmacen.setUpdateSelectionOnSort(false);
        jTableArticulosAlmacen.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableArticulosAlmacenMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableArticulosAlmacen);

        panelabajo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        panelabajo.setLayout(new javax.swing.BoxLayout(panelabajo, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelabajo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE))
                .addGap(28, 28, 28))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(panelabajo, javax.swing.GroupLayout.PREFERRED_SIZE, 484, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTableArticulosAlmacenMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableArticulosAlmacenMouseClicked
        ArticulosAlmacenTableModel ctm=(ArticulosAlmacenTableModel)this.jTableArticulosAlmacen.getModel();
       IArticulosAlmacen articulos=ctm.getRow(this.jTableArticulosAlmacen.getSelectedRow());
        this.panelArticulosAlmacen.setArticulosAlmacen(articulos);
}//GEN-LAST:event_jTableArticulosAlmacenMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ArticulosAlmacenView().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableArticulosAlmacen;
    private javax.swing.JPanel panelabajo;
    // End of variables declaration//GEN-END:variables

    public IArticulosAlmacenController getController() {
        return controller;
    }

    public void setController(IArticulosAlmacenController controller) {
        this.controller=controller;
    }

    public IArticulosAlmacenModel getModel() {
        return model;
    }

    public void setModel(IArticulosAlmacenModel model) {
        this.model=model;
    }

    public void dataModelChanged() {
        refresh();
    }

    public void display() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                setVisible(true);
                refresh();
            }
        });
    }

    protected void refresh() {
        this.tableModel.setArticulosAlmacen(getModel().obtenerArticulosAlmacen());
    }

    protected void fireActualizaArticulosAlmacenGesture(int id, int cantidad, double precio, String nombre, String observaciones,int cantidadComprar) {
        getController().actualizaArticulosAlmacenGesture(id,cantidad,precio,nombre,observaciones,cantidadComprar);
    }

    protected void firedevolverArticulosAlmacenGesture(int id, int cantidad, double precio, String nombre, String observaciones,int cantidadComprar) {
        getController().devolverArticulosAlmacenGesture(id,cantidad,precio,nombre,observaciones,cantidadComprar);
    }

    protected void fireComprarArticulosAlmacenGesture(int id, int cantidad, double precio, String nombre, String observaciones,int cantidadComprar) {
        getController().ComprarArticulosAlmacenGesture(id, cantidad, precio, nombre, observaciones, cantidadComprar);
    }

    public void deshabilitarComprar(){
        this.panelArticulosAlmacen.descomprar();
    }

    public void deshabilitarEncargados(){
        this.panelArticulosAlmacen.desEncargados();
    }
}
